package cn.wd.utils;

import cn.wd.vo.LoginInfo;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class TokenManager {

    private static final Map<String, LoginInfo> TOKEN_MAP = new ConcurrentHashMap<>();
    public static final String TOKEN_NAME = "X-Token";

    public static void put(String token, LoginInfo info) {
        TOKEN_MAP.put(token, info);
    }

    public static LoginInfo get(String token) {
        /*System.out.println(token+"-------");
        System.out.println(TOKEN_MAP.get(token) + "@@@@@@@");*/
        return TOKEN_MAP.get(token);
    }

    public static String getToken() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static Integer size() {
        return TOKEN_MAP.size();
    }

    public static void remove(String token) {
        TOKEN_MAP.remove(token);
    }
}
